﻿using MiniFox.Components;
using MiniFox.Utility;
using Platform.Core.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Platform.Core.Services
{
    public class GenerationService : IGenerationService
    {
        [AutoWired]
        public IGenerationProvider Provider { get; set; }

        public string NewId(string name)
        {
            var returns = this.Provider.NextVal(name);
            var item = returns.Item1;
            var val = returns.Item2;
            var now = item.BasedOnUTCTime ? DateTime.UtcNow : DateTime.Now;
            var id = val.ToString($"D{item.TailLength}");
            return $"{item.Prefix}{now.DateTimeFormat(item.Pattern)}{id}{item.Suffix}";
        }
    }
}
